////////////////////////////////////////////////////////////////////
// File:	Sphere.h
// Purpose: Creates a perfect sphere by using a process called "subdivision"
//			this class also allows you to access it's triangles or normals.
//			This class creates a sphere on the fly.
// Author:	Jay Baird
////////////////////////////////////////////////////////////////////

#ifndef SPHERE_H
#define SPHERE_H

#include "..\..\src\Util\Vector.h"
#include <vector>
#include "MeshComponents.h"

class Sphere
{
public:
	struct VertChunk
	{
		vec3 vertex, normal;
	};

private:
	std::vector<VertChunk> m_verts;
	std::vector<MeshComponent::Triangle> m_triangles;
	
	void CreateTriangle(const vec3& a, const vec3& b, const vec3& c, 
					  unsigned div, float radius);
	void FindVertices(const VertChunk& vertex1, const VertChunk& vertex2, const VertChunk& vertex3,
					  short& i1, short& i2, short& i3);

public:
	Sphere() { }
	~Sphere() { }

	void CreateSphere(unsigned numDivisions, float radius);

	const std::vector<MeshComponent::Triangle>* GetTriangles() const { return &m_triangles; }
	const std::vector<VertChunk>* GetNormalsAndVertices() const { return &m_verts; }
};

inline bool operator==(const Sphere::VertChunk& A, const Sphere::VertChunk& B)
{
	return (A.vertex == B.vertex && A.normal == B.normal);
}

#endif